import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

declare module 'vue-router' {
    // 定义原信息类型
    interface RouteMeta {
        title: string
    }
}
const routes: Array<RouteRecordRaw> = [
    {
        path: "/",
        component: () => import('../App.vue'),
        meta: {
            title: "主页"
        },
    }, {
        path: "/test",
        component: () => import('../components/util/PlaceGetAll.vue'),
        meta: {
            title: "测试"
        },
    }, {
        path: "/Login",
        component: () => import('../components/user/UserLogin.vue'),
        meta: {
            title: "用户登录"
        },
    }, {
        path: "/Registration",
        component: () => import('../components/user/UserRegistration.vue'),
        meta: {
            title: "用户注册"
        },
    }, {
        path: "/UserOperate",
        component: () => import('../components/useroperate/UserOperate.vue'),
        meta: {
            title: "用户页"
        },
        children: [
            {
                path: "",
                component: () => import('../components/useroperate/Shop.vue'),
                meta: {
                    title: "店铺"
                },
            }, {
                path: "Shop",
                component: () => import('../components/useroperate/Shop.vue'),
                meta: {
                    title: "店铺"
                },
            }, {
                path: "Commodity",
                component: () => import('../components/useroperate/Commodity.vue'),
                meta: {
                    title: "商品"
                },
            }, {
                path: "Order",
                component: () => import('../components/useroperate/Order.vue'),
                meta: {
                    title: "我的订单"
                },
            },
            {
                path: "Address",
                component: () => import('../components/useroperate/Address.vue'),
                meta: {
                    title: "我的地址"
                },
            },
            {
                path: "Coupon",
                component: () => import('../components/useroperate/Coupon.vue'),
                meta: {
                    title: "我的优惠卷"
                },
            },
            {
                path: "Evaluate",
                component: () => import('../components/useroperate/Evaluate.vue'),
                meta: {
                    title: "我的评价"
                },
            },
        ]
    },
    {
        path: "/ShopCreate",
        component: () => import('../components/shop/ShopCreate.vue'),
        meta: {
            title: "用户注册"
        },
    },
    {
        path: "/SellerOperate",
        component: () => import('../components/selleroperate/SellerOperate.vue'),
        meta: {
            title: "卖家管理页"
        },
        children: [
            {
                path: "",
                component: () => import('../components/selleroperate/Shop.vue'),
                meta: {
                    title: "店铺"
                },
            }, {
                path: "Shop",
                component: () => import('../components/selleroperate/Shop.vue'),
                meta: {
                    title: "店铺"
                },
            }, {
                path: "Commodity",
                component: () => import('../components/selleroperate/Commodity.vue'),
                meta: {
                    title: "商品"
                },
            }, 
             {
                path: "Order",
                component: () => import('../components/selleroperate/Order.vue'),
                meta: {
                    title: "我的订单"
                },
            },
            {
                path: "Address",
                component: () => import('../components/useroperate/Address.vue'),
                meta: {
                    title: "我的地址"
                },
            },
            {
                path: "Coupon",
                component: () => import('../components/selleroperate/Coupon.vue'),
                meta: {
                    title: "我的优惠卷"
                },
            },
            {
                path: "Evaluate",
                component: () => import('../components/selleroperate/Evaluate.vue'),
                meta: {
                    title: "我的评价"
                },
            },

        ]
    },
]
const router = createRouter({
    history: createWebHistory(),
    scrollBehavior: (to: any, from: any, savePosition: any) => {
        // 确保页面切换时保持上次滚动位置
        if (savePosition) {
            return savePosition
        } else {
            return {
                top: 0
            }
        }

    },
    routes
})

export default router